package net.dopan.pigframe.core.utils;

import net.dopan.pigframe.core.base.controller.response.PageBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

/**
 * @Package: net.dopan.pigframe.core.utils
 * @Title: PageUtils
 * @Description: 分页工具类
 * @author: 刘宽
 * @date: 2018/8/8 13:10
 */
public class PageUtils {

    public static PageBean pageToPageBean(Page page) {
        return PageBean.builder()
                .content(page.getContent())
                .size(page.getSize())
                .total((int) page.getTotalElements())
                .page(page.getNumber())
                .build();
    }

    public static PageRequest pageBeanToPage(PageBean page) {
        return page == null || page.getPage() == null ? PageRequest.of(0, 20) : PageRequest.of(page.getPage(), page.getSize());
    }

}

